<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/10/9 0009
 * Time: 9:48
 */
namespace app\admin\controller;
use app\admin\model\AdminUser;
use think\Request;

class AdminApi
{
    public function admin_login(Request $request){
        $data = $request->param();
        //检测数据是否符合规则
        $val = val($data,['adminuser'=>'require','pwd'=>'require']);
        if(!$val['code']){
            return json(['code'=>205,'msg'=>$val['msg']]);
        }
//        return $data['adminuser'];
        //获取后台用户数据，查看账号是否存在
        if(!$user = AdminUser::getAdminUser(['admin_user'=>$data['adminuser']])){
            return json(['code'=>206,'msg'=>'账号不存在']);
        }
//        return md5(md5($data['pwd']));
    if($user['admin_pwd']==AdminUser::getPwd($data['pwd'])){
            session('adminuser',$user);
            return json(['code'=>200,'msg'=>'登录成功']);
        }else{
        return json(['code'=>503,'msg'=>'账号或密码错误']);
        }
    }
}